package com.gjintel.business.proj.service.impl;

import java.text.SimpleDateFormat;
import java.util.List;

import com.gjintel.auction.business.model.AuctionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gjintel.business.proj.model.ProjectBidInfo;
import com.gjintel.business.proj.model.ProjectInfo;
import com.gjintel.business.proj.service.INotifyService;
import com.gjintel.framework.constant.ActivitiMap;
import com.gjintel.framework.log.model.TSysWarningLog;
import com.gjintel.framework.log.service.impl.MessageServiceImpl;
import com.gjintel.framework.register.model.RegisterUser;
import com.gjintel.framework.register.service.IRegisterUserService;
import com.gjintel.framework.role.model.Role;
import com.gjintel.framework.role.service.IRoleService;
import com.gjintel.framework.user.model.User;

@Service("notifyService")
public class NotifyServiceImpl implements INotifyService {

	@Autowired
	private ProjectInfoServiceImpl projectInfoService;
	
	@Autowired
	private MessageServiceImpl messageService;
	
	@Autowired
	private IRoleService roleService;
	
	@Autowired
	private IRegisterUserService registerUserService;
	
	private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	private static String AUDIT_LOG="1"//审核结果 
						 ,ASSIGN="2"//受理分配信息
						,ESTABLISH="3"//编制结果
						,OPEN_BID="4"//开标
						,SUSPEND="5"//暂停
						,CANCEL="6"//撤销
						,BID_NOTICE="7"//中标公示
						,BID_NOTICE_END="8"//中标公示结束
						,FAIL="9"//流标
						,CONTRACT_NOTICE="10"//合同公示
						,CONTRACT_NOTICE_END="11"//合同公示结束
						,SYS_INFO="0";//系统信息

	@Override
	public void saveWaitAuditNotify(ProjectInfo pi) {
		//提醒审核人，项目待审核
		//获取审核人集合
		List<User> auditList=roleService.findUserByRoleId(ActivitiMap.AUDITOR_ID);
		for (User audit : auditList) {
			TSysWarningLog warningLog = new TSysWarningLog();
			warningLog.setTitle("项目审核");
			warningLog.setContents("您有个待审核项目："+pi.getName()+",请及时审核。");
			warningLog.setProjectId(pi.getId());
			warningLog.setWarnType(AUDIT_LOG);
			warningLog.setReaderId(audit.getId());
			warningLog.setReaderName(audit.getLoginName());
			warningLog.setWarringId("");
			
			messageService.saveOrUpdate(warningLog);
		}
	}

	@Override
	public void saveNoAuditNotify(ProjectInfo pi) {
		//提醒采购人，审核不通过
		TSysWarningLog warningLog=new TSysWarningLog();
		User reader=this.projectInfoService.get(User.class, pi.getCreateId());
		warningLog.setTitle("项目审核");
		warningLog.setContents("您的"+pi.getName()+"项目审核不通过。");
		warningLog.setProjectId(pi.getId());
		warningLog.setWarnType(AUDIT_LOG);
		warningLog.setReaderId(reader.getId());
		warningLog.setReaderName(reader.getLoginName());
		warningLog.setWarringId("");
		messageService.saveOrUpdate(warningLog);
	}
	
	@Override
	public void saveAuditNotify(ProjectInfo pi) {
		//提醒采购人，审核通过
		TSysWarningLog warningLog=new TSysWarningLog();
		User reader=this.projectInfoService.get(User.class, pi.getCreateId());
		warningLog.setTitle("项目审核");
		warningLog.setContents("您的"+pi.getName()+"项目审核通过。");
		warningLog.setProjectId(pi.getId());
		warningLog.setWarnType(AUDIT_LOG);
		warningLog.setReaderId(reader.getId());
		warningLog.setReaderName(reader.getLoginName());
		warningLog.setWarringId("");
		messageService.saveOrUpdate(warningLog);
	}
	
	@Override
	public void saveWaitAssignNotify(ProjectInfo pi) {
		//提醒分配人，项目待分配
		//获取分配人集合
		List<User> assignList = roleService.findUserByRoleId(ActivitiMap.SYSTEM_ID);
		for (User assign : assignList) {
			TSysWarningLog warningLog = new TSysWarningLog();
			warningLog.setTitle("项目审核");
			warningLog.setContents("您有个待分配项目：" + pi.getName() + ",请及时分配项目负责人。");
			warningLog.setProjectId(pi.getId());
			warningLog.setWarnType(AUDIT_LOG);
			warningLog.setReaderId(assign.getId());
			warningLog.setReaderName(assign.getLoginName());
			warningLog.setWarringId("");
			messageService.saveOrUpdate(warningLog);
		}
	}

	@Override
	public void saveAssignNotify(ProjectInfo pi) {
		//提醒项目负责人，待编制
		TSysWarningLog warningLog=new TSysWarningLog();
		warningLog.setTitle("项目编制");
		warningLog.setContents("您有个待编制项目：" + pi.getName() + ",请及时编制。");
		warningLog.setProjectId(pi.getId());
		warningLog.setWarnType(ESTABLISH);
		warningLog.setReaderId(pi.getManageId());
		warningLog.setReaderName(pi.getManageName());
		warningLog.setWarringId("");
		messageService.saveOrUpdate(warningLog);
	}
	
	@Override
	public void saveWaitEstablishNotify(ProjectInfo pi) {
		//提醒采购人，有一个项目竞价文件待确认
		TSysWarningLog warningLog=new TSysWarningLog();
		User reader=this.projectInfoService.get(User.class, pi.getCreateId());
		warningLog.setTitle("项目编制");
		warningLog.setContents("您的"+pi.getName()+"项目竞价文件已编制，请及时确认。");
		warningLog.setProjectId(pi.getId());
		warningLog.setWarnType(ESTABLISH);
		warningLog.setReaderId(reader.getId());
		warningLog.setReaderName(reader.getLoginName());
		warningLog.setWarringId("");
		messageService.saveOrUpdate(warningLog);
	}
	
	@Override
	public void saveNoEstablishNotify(ProjectInfo pi) {
		//提醒项目负责人，编制确认不通过
		TSysWarningLog warningLog = new TSysWarningLog();
		warningLog.setTitle("项目编制");
		warningLog.setContents("您的"+pi.getName()+"项目竞价文件确认不通过，请及时处理。");
		warningLog.setProjectId(pi.getId());
		warningLog.setWarnType(ESTABLISH);
		warningLog.setReaderId(pi.getManageId());
		warningLog.setReaderName(pi.getManageName());
		warningLog.setWarringId("");
		messageService.saveOrUpdate(warningLog);
	}
	
	@Override
	public void saveOvertimeEstablishNotify(ProjectInfo pi) {
		//提醒项目负责人，超时未确认
		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目编制");
		managerLog.setContents("您的"+pi.getName()+"项目竞价文件超时未被确认，请及时处理。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(ESTABLISH);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
	}

	@Override
	public void saveEstablishNotify(ProjectInfo pi) {
		//提醒采购人，项目负责人，竞价文件已确认，公告已发布
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目编制");
		buyerLog.setContents("您的"+pi.getName()+"项目竞价公告已发布。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目编制");
		managerLog.setContents("您的"+pi.getName()+"项目竞价公告已发布。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(OPEN_BID);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
		
	}
	
	@Override
	public void saveSuspendCompeleNotify(ProjectInfo pi) {
		//提醒采购人，项目负责人，竞价公示期暂停
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目编制");
		buyerLog.setContents("您的" + pi.getName() + "项目竞价公告已暂停。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目编制");
		managerLog.setContents("您的" + pi.getName() + "项目竞价公告已暂停。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(OPEN_BID);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
	}

	@Override
	public void saveWaitSuspendCompeleAudtiNotify(ProjectInfo pi) {
		//提醒业务管理员,项目竞价公示期暂停待审核
		//获取业务管理员集合
		List<User> businessManagerList = roleService.findUserByRoleId(ActivitiMap.BIZMANAGER_ID);
		for (User business : businessManagerList) {
			TSysWarningLog warningLog = new TSysWarningLog();
			warningLog.setTitle("项目暂停");
			warningLog.setContents("您有个暂停待审核项目：" + pi.getName() + ",请及时审核。");
			warningLog.setProjectId(pi.getId());
			warningLog.setWarnType(SUSPEND);
			warningLog.setReaderId(business.getId());
			warningLog.setReaderName(business.getLoginName());
			warningLog.setWarringId("");
			messageService.saveOrUpdate(warningLog);
		}
	}

	@Override
	public void saveStartCompeleNotify(ProjectInfo pi) {
		//提醒采购人，项目负责人，竞价公告重启
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目暂停");
		buyerLog.setContents("您的" + pi.getName() + "项目竞价公告已重启，开标时间变更为"+sdf.format(pi.getBidStartTime())+"。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目暂停");
		managerLog.setContents("您的" + pi.getName() + "项目竞价公告已重启，开标时间变更为"+sdf.format(pi.getBidStartTime())+"。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(OPEN_BID);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
	}

	@Override
	public void saveCancelProjectNotify(ProjectInfo pi) {
		//提醒采购人,项目负责人，项目撤销
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目撤销");
		buyerLog.setContents("您的" + pi.getName() + "项目已撤销。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(CANCEL);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目撤销");
		managerLog.setContents("您的" + pi.getName() + "项目已撤销。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(CANCEL);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
	}

	@Override
	public void saveOpenBidNotify(ProjectInfo pi) {
		//提醒采购人、项目负责人、本项目投标人，项目已开标
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目开标");
		buyerLog.setContents(""+pi.getName()+"项目已于"+sdf.format(pi.getBidStartTime())+"开标，请及时处理。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目开标");
		managerLog.setContents(""+pi.getName()+"项目已于"+sdf.format(pi.getBidStartTime())+"开标，请及时处理。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(OPEN_BID);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
		
		//投标人
		//获取投标人集合
		ProjectBidInfo bidInfo=new ProjectBidInfo();
		bidInfo.setProjectId(pi.getId());
		List<ProjectBidInfo> bidInfoList = projectInfoService.findProjectBidListByProjectId(null, bidInfo);
		for (ProjectBidInfo bidder : bidInfoList) {
			TSysWarningLog bidderLog = new TSysWarningLog();
			bidderLog.setTitle("项目开标");
			bidderLog.setContents(""+pi.getName()+"项目已于"+sdf.format(pi.getBidStartTime())+"开标，请及时处理。");
			bidderLog.setProjectId(pi.getId());
			bidderLog.setWarnType(OPEN_BID);
			bidderLog.setReaderId(bidder.getUserId());
			bidderLog.setReaderName(bidder.getBidderName());
			bidderLog.setWarringId("");
			messageService.saveOrUpdate(bidderLog);
		}
	}
	
	@Override
	public void saveEndEvaluateNotify(ProjectInfo pi) {
		//提醒采购人，项目评标结束
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目开标");
		buyerLog.setContents("您的" + pi.getName() + "项目已完成评标，请及时确认评标结果。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);
	}
	
	@Override
	public void saveWinBiddingNoticeNotify(ProjectInfo pi) {
		//提醒采购人、项目负责人、本项目投标人，中标公示已发布
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目中标公示");
		buyerLog.setContents("" + pi.getName() + "项目中标公示已发布，请注意查看。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(BID_NOTICE);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目中标公示");
		managerLog.setContents("" + pi.getName() + "项目中标公示已发布，请注意查看。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(BID_NOTICE);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);

		// 投标人
		// 获取投标人集合
		ProjectBidInfo bidInfo=new ProjectBidInfo();
		bidInfo.setProjectId(pi.getId());
		List<ProjectBidInfo> bidInfoList = projectInfoService.findProjectBidListByProjectId(null, bidInfo);
		for (ProjectBidInfo bidder : bidInfoList) {
			TSysWarningLog bidderLog = new TSysWarningLog();
			bidderLog.setTitle("项目中标公示");
			bidderLog.setContents("" + pi.getName() + "项目中标公示已发布，请注意查看。");
			bidderLog.setProjectId(pi.getId());
			bidderLog.setWarnType(BID_NOTICE);
			bidderLog.setReaderId(bidder.getId());
			bidderLog.setReaderName(bidder.getBidderName());
			bidderLog.setWarringId("");
			messageService.saveOrUpdate(bidderLog);
		}
	}

	@Override
	public void saveFailBidNotify(ProjectInfo pi) {
		//提醒采购人、项目负责人、本项目投标人，流标公示已发布
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目流标公示");
		buyerLog.setContents("" + pi.getName() + "项目流标公示已发布，请注意查看。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(BID_NOTICE);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目流标公示");
		managerLog.setContents("" + pi.getName() + "项目流标公示已发布，请注意查看。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(BID_NOTICE);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);

		// 投标人
		// 获取投标人集合
		ProjectBidInfo bidInfo=new ProjectBidInfo();
		bidInfo.setProjectId(pi.getId());
		List<ProjectBidInfo> bidInfoList = projectInfoService.findProjectBidListByProjectId(null, bidInfo);
		for (ProjectBidInfo bidder : bidInfoList) {
			TSysWarningLog bidderLog = new TSysWarningLog();
			bidderLog.setTitle("项目流标公示");
			bidderLog.setContents("" + pi.getName() + "项目流标公示已发布，请注意查看。");
			bidderLog.setProjectId(pi.getId());
			bidderLog.setWarnType(BID_NOTICE);
			bidderLog.setReaderId(bidder.getId());
			bidderLog.setReaderName(bidder.getBidderName());
			bidderLog.setWarringId("");
			messageService.saveOrUpdate(bidderLog);
		}
	}

	@Override
	public void saveSuspendWinBidingNotify(ProjectInfo pi) {
		//提醒采购人、项目负责人、中标人，中标公示暂停
		// 采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目编制");
		buyerLog.setContents("您的" + pi.getName() + "项目中标公告已暂停。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目编制");
		managerLog.setContents("您的" + pi.getName() + "项目中标公告已暂停。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(OPEN_BID);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
		
		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("项目流标公示");
		bidderLog.setContents("您的" + pi.getName() + "项目中标公告已暂停。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(BID_NOTICE);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveWaitSuspendWinBiddingAudtiNotify(ProjectInfo pi) {
		//提醒业务管理员，项目中标公示期暂停待审核
		//获取业务管理员集合
		List<User> businessManagerList = roleService.findUserByRoleId(ActivitiMap.BIZMANAGER_ID);
		for (User business : businessManagerList) {
			TSysWarningLog warningLog = new TSysWarningLog();
			warningLog.setTitle("项目暂停");
			warningLog.setContents("您有个暂停待审核项目：" + pi.getName() + ",请及时审核。");
			warningLog.setProjectId(pi.getId());
			warningLog.setWarnType(SUSPEND);
			warningLog.setReaderId(business.getId());
			warningLog.setReaderName(business.getLoginName());
			warningLog.setWarringId("");
			messageService.saveOrUpdate(warningLog);
		}
	}

	@Override
	public void saveStartWinBiddingNotify(ProjectInfo pi) {
		//提醒采购人、项目负责人、中标人，中标公示重启
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目暂停");
		buyerLog.setContents("您的" + pi.getName() + "项目中标公告已重启，公告截止时间变更为" + sdf.format(pi.getShowEndTime()) + "。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(OPEN_BID);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目暂停");
		managerLog.setContents("您的" + pi.getName() + "项目中标公告已重启，公告截止时间变更为" + sdf.format(pi.getShowEndTime()) + "。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(OPEN_BID);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);
		
		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("项目暂停");
		bidderLog.setContents("您的" + pi.getName() + "项目中标公告已重启，公告截止时间变更为" + sdf.format(pi.getShowEndTime()) + "。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(BID_NOTICE);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveFialWinBiddingNotify(ProjectInfo pi) {
		//提醒采购人、项目负责人、中标人，项目流标
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目流标");
		buyerLog.setContents("您的" + pi.getName() + "项目已流标。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(FAIL);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 项目负责人
		TSysWarningLog managerLog = new TSysWarningLog();
		managerLog.setTitle("项目流标");
		managerLog.setContents("您的" + pi.getName() + "项目已流标。");
		managerLog.setProjectId(pi.getId());
		managerLog.setWarnType(FAIL);
		managerLog.setReaderId(pi.getManageId());
		managerLog.setReaderName(pi.getManageName());
		managerLog.setWarringId("");
		messageService.saveOrUpdate(managerLog);

		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("项目流标");
		bidderLog.setContents("您的" + pi.getName() + "项目已流标。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(FAIL);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveAlertNotify(ProjectInfo pi) {
		//提醒采购人、中标人，中标通知书发放
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("项目签约");
		buyerLog.setContents("您的" + pi.getName() + "项目中标通知书已发放。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(BID_NOTICE_END);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("项目签约");
		bidderLog.setContents("您的" + pi.getName() + "项目中标通知书已发放。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(BID_NOTICE_END);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
		
		//财务管理员
		List<User> financelist = roleService.findUserByRoleId(ActivitiMap.FINANCE_ID);
		for(User finance : financelist){
			TSysWarningLog financeLog = new TSysWarningLog();
			financeLog.setTitle("退还非中标保证金");
			financeLog.setContents("您好," + pi.getName() + "项目的非中标保证金可以开始退还。");
			financeLog.setProjectId(pi.getId());
			financeLog.setWarnType(BID_NOTICE_END);
			financeLog.setReaderId(finance.getId());
			financeLog.setReaderName(finance.getName());
			financeLog.setWarringId("");
			messageService.saveOrUpdate(financeLog);
		  }  
		}
		
		

	@Override
	public void saveBackNoWinBiddingBallNotify(ProjectInfo pi) {
		//提醒非中标人，投标保证金已退
		//获取投标投标人集合
		List<User> bidderList = roleService.findUserByRoleId(ActivitiMap.BIZMANAGER_ID);
		for (User bidder : bidderList) {
			RegisterUser register = registerUserService.get(RegisterUser.class, bidder.getRegisterId());
			if(register!=null&&!register.equals(pi.getWinningId())){//非中标人
				TSysWarningLog warningLog = new TSysWarningLog();
				warningLog.setTitle("项目退回保证金");
				warningLog.setContents("" + pi.getName() + "，项目非中标人投标保证金已退，请近视办理手续。");
				warningLog.setProjectId(pi.getId());
				warningLog.setWarnType(BID_NOTICE_END);
				warningLog.setReaderId(register.getId());
				warningLog.setReaderName(register.getName());
				warningLog.setWarringId("");
				messageService.saveOrUpdate(warningLog);
			}
		}
	}

	@Override
	public void saveDeductedNoWinBiddingBall(ProjectInfo pi) {
		//23、提醒非中标人，投标保证金已被扣除 
		//获取投标投标人集合
		List<User> bidderList = roleService.findUserByRoleId(ActivitiMap.BIZMANAGER_ID);
		for (User bidder : bidderList) {
			RegisterUser register = registerUserService.get(RegisterUser.class, bidder.getRegisterId());
			if (register != null && !register.equals(pi.getWinningId())) {// 非中标人
				TSysWarningLog warningLog = new TSysWarningLog();
				warningLog.setTitle("项目扣除保证金");
				warningLog.setContents("" + pi.getName() + "，项目非中标人投标保证金已扣除。");
				warningLog.setProjectId(pi.getId());
				warningLog.setWarnType(BID_NOTICE_END);
				warningLog.setReaderId(register.getId());
				warningLog.setReaderName(register.getName());
				warningLog.setWarringId("");
				messageService.saveOrUpdate(warningLog);
			}
		}
	}

	@Override
	public void saveContractAuditNotify(ProjectInfo pi) {
		//提醒采购人，中标人，合同审核通过
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("合同审核");
		buyerLog.setContents("您的" + pi.getName() + "项目已审核通过，合同公示中。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(CONTRACT_NOTICE);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("合同审核");
		bidderLog.setContents("您的" + pi.getName() + "项目已审核通过，合同公示中。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(CONTRACT_NOTICE);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveContractNoAuditNotify(ProjectInfo pi) {
		//提醒采购人，中标人，合同审核不通过
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("合同审核");
		buyerLog.setContents("您的" + pi.getName() + "项目合同已审核不通过，请重新上传。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(CONTRACT_NOTICE);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("合同审核");
		bidderLog.setContents("您的" + pi.getName() + "项目合同已审核不通过，请重新上传。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(CONTRACT_NOTICE);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveBackWinBiddingBailNotify(ProjectInfo pi) {
		//提醒中标人，退投标保证金已退
		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("项目退回保证金");
		bidderLog.setContents("您的" + pi.getName() + "项目投标保证金已退，请及时办理手续。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(CONTRACT_NOTICE);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveAcceptanceAudtiNotify(ProjectInfo pi) {
		//采购人
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("验收报告审核");
		buyerLog.setContents("您的" + pi.getName() + "项目验收报告已审核通过，验收报告公示中。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(CONTRACT_NOTICE_END);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("验收报告审核");
		bidderLog.setContents("您的" + pi.getName() + "项目验收报告已审核通过，验收报告公示中。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(CONTRACT_NOTICE_END);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void saveAcceptanceNoAudtiNotify(ProjectInfo pi) {
		//提醒采购人，中标人，验收报告不通过
		TSysWarningLog buyerLog = new TSysWarningLog();
		User reader = this.projectInfoService.get(User.class, pi.getCreateId());
		buyerLog.setTitle("验收报告审核");
		buyerLog.setContents("您的" + pi.getName() + "项目验收报告已审核不通过，请重新上传。");
		buyerLog.setProjectId(pi.getId());
		buyerLog.setWarnType(CONTRACT_NOTICE_END);
		buyerLog.setReaderId(reader.getId());
		buyerLog.setReaderName(reader.getLoginName());
		buyerLog.setWarringId("");
		messageService.saveOrUpdate(buyerLog);

		// 中标人
		TSysWarningLog bidderLog = new TSysWarningLog();
		bidderLog.setTitle("验收报告审核");
		bidderLog.setContents("您的" + pi.getName() + "项目验收报告已审核不通过，请重新上传。");
		bidderLog.setProjectId(pi.getId());
		bidderLog.setWarnType(CONTRACT_NOTICE_END);
		bidderLog.setReaderId(pi.getWinningId());
		bidderLog.setReaderName(pi.getWinningName());
		bidderLog.setWarringId("");
		messageService.saveOrUpdate(bidderLog);
	}

	@Override
	public void savePostBankFallNotify(AuctionInfo pi) {
		// 提醒系统管理员 三次推送项目信息至银行生成虚拟子账号失败
		
		List<User> adminList = roleService.findUserByRoleId(ActivitiMap.ADMINISTRATOR_ID);
		for (User admin : adminList) {
			TSysWarningLog bidderLog = new TSysWarningLog();
			bidderLog.setTitle("系统信息");
			bidderLog.setContents("项目" + pi.getAuctionName() + "信息推送至银行失败，请处理！");
			bidderLog.setProjectId(pi.getId());
			bidderLog.setWarnType(SYS_INFO);
			bidderLog.setReaderId(admin.getId());
			bidderLog.setReaderName(admin.getLoginName());
			bidderLog.setWarringId("");
			messageService.saveOrUpdate(bidderLog);
		}
	}

	@Override
	public void saveMessageByRoles(TSysWarningLog message, List<Role> roles) {
		for (Role role : roles) {
			List<User> userList = roleService.findUserByRoleId(role.getId());
			for (User user : userList) {
				TSysWarningLog log = new TSysWarningLog();
				log.setTitle(message.getTitle());
				log.setContents(message.getContents());
				log.setProjectId(message.getProjectId());
				log.setWarnType(SYS_INFO);
				if(role.getId().equals(ActivitiMap.BIDDER_ID)){//为投标人
					RegisterUser register = registerUserService.get(RegisterUser.class, user.getRegisterId());
					log.setReaderId(register.getId());
				}else{
					log.setReaderId(user.getId());
				}
				log.setReaderName(user.getLoginName());
				log.setWarringId("");
				messageService.saveOrUpdate(log);
			}
		}
	}

}
